# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Jürgen Pfeifer <juergen@familiepfeifer.de>

pkgname=lftp
pkgver=4.8.4
pkgrel=1
pkgdesc="Sophisticated command line based FTP client (net-utils)"
arch=('i686' 'x86_64')
license=('GPL3')
groups=('net-utils')
depends=('gcc-libs'
         'ca-certificates'
         'expat'
         'gettext'
         'libexpat'
         'libgnutls'
         'libiconv'
         'libidn2'
         'libintl'
         'libreadline'
         'libunistring'
         'openssh'
         'zlib')
makedepends=('gcc'
             'gettext-devel'
             'libexpat-devel'
             'libgnutls-devel'
             'libiconv-devel'
             'libidn2-devel'
             'libreadline-devel'
             'libunistring-devel'
             'zlib-devel')
optdepends=('perl: needed for convert-netscape-cookies and verify-file')
url="https://lftp.yar.ru/"
backup=('etc/lftp.conf')
source=(https://lftp.yar.ru/ftp/${pkgname}-${pkgver}.tar.xz{,.asc}
        lftp-configure-needtrio.patch
        lftp-4.8.4-msysize.patch
        lftp-4.7.6-no-undefined.patch
        lftp-correct-gettext-macros.patch)
options=('debug' '!strip')
sha256sums=('4ebc271e9e5cea84a683375a0f7e91086e5dac90c5d51bb3f169f75386107a62'
            'SKIP'
            'a3781d946913a0d39a41d5b86390f255b36f67e9aea502e0117e701e295c7ea0'
            'dd23a090834e4509905e8f220ae10324f430692ac4fc6593b72431b1692990ae'
            'be33e63d4a12bc7e251451890f5e688e3a51303794b3a597bbe70b52e280615f'
            'd6d74b134385e1c3f824b9a960376a2bcb7c0e39acab2ae1c3c764f9d338e650')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/lftp-configure-needtrio.patch
  patch -p1 -i ${srcdir}/lftp-4.8.4-msysize.patch
  patch -p1 -i ${srcdir}/lftp-4.7.6-no-undefined.patch
  patch -p1 -i ${srcdir}/lftp-correct-gettext-macros.patch

  autoreconf -fiv
}

build() {
  [[ -d "build-${CARCH}" ]] && rm -rf "build-${CARCH}"
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}
  ../${pkgname}-${pkgver}/configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --with-gnutls \
    --without-openssl \
    --without-included-regex \
    --with-expat \
    --with-libidn2 \
    --disable-rpath
  make
}

check() {
  cd ${srcdir}/build-${CARCH}
  make -k check
}

package() {

  cd ${srcdir}/build-${CARCH}
  make DESTDIR=${pkgdir} install
  
  grep -q 'set ssl:ca-file' ${pkgdir}/etc/lftp.conf || echo 'set ssl:ca-file /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem' >> ${pkgdir}/etc/lftp.conf

}
